package com.wn.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wn.dao.CateringDao;
import com.wn.entity.Catering;
import com.wn.entity.Hotelinfo;
import com.wn.entity.Scenic;
import com.wn.service.CateringService;
import com.wn.utils.PageParam;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

/**
 * (Catering)表服务实现类
 *
 * @author makejava
 * @since 2020-10-26 09:28:42
 */
@Service("cateringService")
@Transactional(rollbackFor = Exception.class)
public class CateringServiceImpl implements CateringService {
    @Resource
    private CateringDao cateringDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Catering queryById(String id) {
        return this.cateringDao.queryById(id);
    }




    @Override
    public PageInfo<Catering> searchSomeByPage(PageParam<Catering> pageParam) {
        if(!StringUtils.isEmpty(pageParam.getSuperSearchKeyWord())){
            //执行高级检索
            //分页
            PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
            //排序
            for(int i=0;i<pageParam.getOrderParams().length;i++){
                PageHelper.orderBy(pageParam.getOrderParams()[i]);
            }


            List<Catering> orderList=cateringDao.superSearch(pageParam.getSuperSearchKeyWord());
            PageInfo<Catering> orderPageInfo = new PageInfo<Catering>(orderList);

            return orderPageInfo;

        }else{
            //分页
            PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
            //排序
            for(int i=0;i<pageParam.getOrderParams().length;i++){
                PageHelper.orderBy(pageParam.getOrderParams()[i]);
            }


            List<Catering> orderList=cateringDao.searchSomeByPage(pageParam.getModel());
            PageInfo<Catering> orderPageInfo = new PageInfo<Catering>(orderList);

            return orderPageInfo;

        }
    }


    /**
     * 新增数据
     *
     * @param catering 实例对象
     * @return 实例对象
     */
    @Override
    public Integer insert(Catering catering) {
        catering.setId(UUID.randomUUID().toString().replaceAll("-","")+"_catering");
        catering.setIsdeleted(0);
        return this.cateringDao.insert(catering);
    }

    /**
     * 修改数据
     *
     * @param catering 实例对象
     * @return 实例对象
     */
    @Override
    public Integer update(Catering catering) {
        return this.cateringDao.update(catering);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.cateringDao.deleteById(id) > 0;
    }

    @Override
    public List<Catering> selcatering(Object longitude, Object latitude) {
        List<Catering> catering = cateringDao.selcatering(longitude, latitude);
        return catering;
    }


}